package org.jsbd.boss.service.impl;

import java.util.List;
import java.util.Map;

import org.jsbd.boss.common.DataGridModel;
import org.jsbd.boss.dao.ICabinetConfigDao;
import org.jsbd.boss.domian.CabinetConfigBean;
import org.jsbd.boss.service.ICabinetConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("cabinetConfigService")
public class CabinetConfigServiceImpl implements ICabinetConfigService {

	@Autowired
	private ICabinetConfigDao cabinetConfigDao;

	@Override
	public void saveCabinetConfig(CabinetConfigBean CabinetConfig){
		cabinetConfigDao.saveCabinetConfig(CabinetConfig);
	}

	@Override
	public void updateCabinetConfig(CabinetConfigBean CabinetConfig){
		cabinetConfigDao.updateCabinetConfig(CabinetConfig);
	}

	@Override
	public CabinetConfigBean getCabinetConfig(CabinetConfigBean CabinetConfig) {
		return cabinetConfigDao.getCabinetConfig(CabinetConfig);
	}

	@Override
	public List<CabinetConfigBean> getCabinetConfigList(CabinetConfigBean CabinetConfig) {
		return cabinetConfigDao.getCabinetConfigList(CabinetConfig);
	}

	@Override
	public Map<String, Object> getCabinetConfigListPage(DataGridModel page, CabinetConfigBean CabinetConfig) {
		return cabinetConfigDao.getCabinetConfigListPage(page, CabinetConfig);
	}

	@Override
	public Integer getCabinetConfigCount(CabinetConfigBean CabinetConfig) {
		return cabinetConfigDao.getCabinetConfigCount(CabinetConfig);
	}
	
	@Override
	public void deleteCabinetConfig(CabinetConfigBean CabinetConfig) {
		cabinetConfigDao.deleteCabinetConfig(CabinetConfig);
	}

	@Override
	public boolean validateSaveCabinetConfig(CabinetConfigBean cabinetConfig) {
		List<CabinetConfigBean> dataList=cabinetConfigDao.validateCabinetConfig(cabinetConfig);
		if(dataList==null||dataList.isEmpty()){
			return true;
		}
		return false;
	}
	
	@Override
	public boolean validateUpdateCabinetConfig(CabinetConfigBean cabinetConfig) {
		int id=cabinetConfig.getId();
		List<CabinetConfigBean> dataList=cabinetConfigDao.validateCabinetConfig(cabinetConfig);
		if(dataList==null||dataList.isEmpty()){
			return true;
		}
		
		for(CabinetConfigBean config:dataList){
			if(config.getId()!=id){
				return false;
			}
		}
		
		return true;
	}

	@Override
	public Map<String, String> getCabinetConfigAllMap() {
		Map<String, String> map = new java.util.HashMap<>();
		List<CabinetConfigBean> configList=cabinetConfigDao.getCabinetConfigList(new CabinetConfigBean());
		for (CabinetConfigBean cabinetConfigBean : configList) {
			map.put(cabinetConfigBean.getIpSection(), cabinetConfigBean.getLocation());
		}
		return map;
	}
	
}
